package cn.dt70.services.impl;

import cn.dt70.dao.appInfo.AppInfoMapper;
import cn.dt70.pojo.AppInfo;
import cn.dt70.services.AppInfoService;
import cn.dt70.utils.PageHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service("appInfoService")
public class AppInfoServiceImpl implements AppInfoService {
    private static final Logger logger = Logger.getLogger(UserServiceImpl.class);
    @Resource
    private AppInfoMapper appInfoMapper;
    //    查看app信息列表
    @Override
    public List<AppInfo> qryAllAPP(PageHelper ph,String querySoftwareName,Integer status,Integer flatformId,
                                   Integer categoryLevel1,Integer categoryLevel2,Integer categoryLevel3) {
        List<AppInfo> appInfoList= new ArrayList<>();
        try {
            ph.setTotalCount( appInfoMapper.qryAppCount(querySoftwareName, status,flatformId,categoryLevel1,categoryLevel2,categoryLevel3) );
            appInfoList = appInfoMapper.qryAppInfoAll((ph.getCurrentPageNo()-1)*ph.getPageSize(),ph.getPageSize(),querySoftwareName,status,flatformId,categoryLevel1,categoryLevel2,categoryLevel3);
            if (appInfoList.size() <= 0) {
                logger.debug("AppInfoServiceImpl.qryAllAPP 查询为空！");
                //return userList;
            } else {
                logger.debug("AppInfoServiceImpl.qryAllAPP 查询成功！");
            }
        } catch (Exception e) {
            logger.error("AppInfoServiceImpl.qryAllAPP 异常！"+e.getMessage());
        }
        return appInfoList;
    }
//查询App总记录数
    @Override
    public Integer qryAppCount(String querySoftwareName,Integer status,Integer flatformId,Integer categoryLevel1,Integer categoryLevel2,Integer categoryLevel3) {
        int count = 0;
        try {
            count = appInfoMapper.qryAppCount(querySoftwareName, status,flatformId,categoryLevel1,categoryLevel2,categoryLevel3);
        } catch (Exception e) {
            logger.error("AppInfoServiceImpl.qryAppCount 异常！"+e.getMessage());
        }
        return count;
    }
    @Override
    public AppInfo getAppInfo(Integer id)  {
        AppInfo appInfo = new AppInfo();
        try {
            appInfo=  appInfoMapper.getAppInfo(id);
        } catch (Exception e) {
            logger.error("AppInfoServiceImpl.getAppInfo 异常！"+e.getMessage());
        }
        return appInfo;
    }

    //修改info状态，上下架
    @Override
    public AppInfo updateAppInfoById(long id, long status) {
        AppInfo appInfo = new AppInfo();
        try {
            appInfo = appInfoMapper.updateAppInfoById(id,status);
            if (null == appInfo){
                logger.debug("AppInfoServiceImpl.updateAppInfoById 为空");
            }else {
                logger.debug("AppInfoServiceImpl.updateAppInfoById 成功");
            }
        } catch (Exception e) {
            logger.error("AppInfoServiceImpl.updateAppInfoById 异常！"+e.getMessage());
        }
        return appInfo;
    }

    @Override
    public boolean removerAppInfo(int appId) {
        int row=0;
        try {
            row=appInfoMapper.del(appId);
            if(row !=1){
                logger.debug("AppInfoServiceImpl.removerAppInfo删除失败！");
                return false;
            }else{
                logger.debug("AppInfoServiceImpl.removerAppInfo删除成功！");
                return true;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("AppInfoServiceImpl.removerAppInfo删除异常："+e.getMessage());
            return false;
        }
    }
}
